package com.ynny.dao;

import com.ynny.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

//配置连接数据

@Repository
public class StudentDaoImpl implements StudentDao{

    //spring里面的 jdbcTemplate
    //跟数据库连接池 进行依赖绑定
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int insert() {

        //修改 添加 删除
        String sql = "insert into student(name,age) values (?,?)";
        int i = jdbcTemplate.update(sql,
                new Object[]{"张三11111", 19});

        return i;

    }

    @Override
    public List<Student> selectAll() {

        String sql = "select * from student";
        List<Student> list = jdbcTemplate
                .query(sql,new BeanPropertyRowMapper<Student>
                                (Student.class)
                );
//        jdbcTemplate.queryForList(sql, new BeanPropertyRowMapper<Student>(Student.class));

        return list;
    }
}
